package com.bank.seckill.service.impl;

import com.bank.entity.Member;
import com.bank.entity.Seckill;
import com.bank.entity.SeckillLog;
import com.bank.seckill.mapper.GoodsMapper;
import com.bank.seckill.service.GoodsService;
import com.bank.um.mapper.MemberMapper;
import com.bank.um.service.MemberService;
import com.bank.utils.FdfsUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author: Lixy
 * @email: 1908598362@qq.com
 * @date: 2022/1/28 星期五 17:45
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Seckill> implements GoodsService {

    @Autowired
    private  GoodsMapper goodsMapper;

    @Autowired
    private FastFileStorageClient fastFileStorageClient;

    public String saveGoods(Seckill goods, MultipartFile image) throws IOException {
        String fullPath = "";
        if (image != null) {
            fullPath = FdfsUtils.uploadFile(fastFileStorageClient, image.getInputStream(), image.getOriginalFilename(), image.getSize());
        } else {
            goods.setGoodsImg(null);
        }
        goodsMapper.insert(goods);
        return fullPath;
    }

   public Seckill SelcetGoodsById(String secid){
        QueryWrapper<Seckill> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("secid",secid);
       Seckill goods = goodsMapper.selectOne(queryWrapper);
       return goods;
   }

    public Seckill SelcetGoodsByName(String name){
        QueryWrapper<Seckill> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",name);
        Seckill goods = goodsMapper.selectOne(queryWrapper);
        return goods;
    }

    public List<Seckill> SelectAll(){
        List<Seckill> seckills = goodsMapper.selectList(null);
        return seckills;
    }

    public Seckill SelectOne(QueryWrapper queryWrapper){
        Seckill goods = goodsMapper.selectOne(queryWrapper);
        return goods;
    }

    public boolean update(UpdateWrapper<Seckill> updateWrapper){
        if (updateWrapper!=null){
            return true;
        }else {
            return false;
        }
    }

}
